import { useMemo } from 'react'
import useWidget from '@/hooks/useWidget'
import useDataCfg from './useDataCfg'
import useColumns from './useColumns'
import useData from './useData'
import useStyles from './useStyles'
import useSummary from './useSummary'

function useTable(widgetId) {
  const { currentWidget } = useWidget(widgetId)
  const chart = useMemo(() => currentWidget?.styleValue?.chart || {}, [currentWidget])
  const summary = useMemo(() => currentWidget?.styleValue?.summary || {}, [currentWidget])
  const dataCfg = useDataCfg(widgetId)
  console.log(dataCfg)

  const styles = useStyles(chart)
  const _summary = useSummary(summary)

  const { width = 400, height = 300 } = currentWidget?.size || {}

  return {
    s2DataConfig: dataCfg,
    s2Options: {
      width: width - 32,
      height,
      showSeriesNumber: true
    },
    styles,
    summary: _summary
  }
}

export default useTable
